FROM python:3.12-slim


WORKDIR /root
COPY . .
# 写入新的源地址
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware\n\
deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware\n\
deb http://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware\n\
deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware" > /etc/apt/sources.list


#RUN cat <<EOF > /etc/apt/sources.list
#deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
#deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware
#deb http://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware
#deb http://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware
#EOF


# 确保文件权限正确
RUN chmod 644 /etc/apt/sources.list

RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install --upgrade pip setuptools
RUN apt-get update
RUN apt-get install build-essential -y
RUN apt-get install libre2-dev -y
RUN apt-get install python3-dev -y
RUN pip install --no-cache-dir google-re2
RUN pip install apache-airflow==2.10.5


# 设置自定义工作目录
ENV AIRFLOW_HOME=/root/workspace

# 创建自定义工作目录
RUN mkdir -p /root/workspace/dags \
    && mkdir -p /root/workspace/logs \
    && mkdir -p /root/workspace/plugins

WORKDIR /root/workspace

RUN airflow db init

RUN airflow users create \
  --username simon \
  --password lege@123 \
  --firstname Herbert \
  --lastname Simon \
  --role Admin \
  --email simon@airflow.org


EXPOSE 8080
# 设置时区为东八区
ENV TZ=Asia/Shanghai


CMD ["airflow webserver --hostname 0.0.0.0 --port 8080 && airflow scheduler"]
